package com.dsg.workflow;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsg.common.util.toolbox.DateUtil;
import com.dsg.entity.apply.DsgApplyCard;
import com.dsg.entity.approve.DsgApproveCase;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 過期補領
 */
@Service
public class WorkflowService13 extends AbstractWorkflowService {

    @Override
    List<String> determineForwardNodeIdList(DsgApproveCase approveCase, String nodeName) throws Exception {
        List<String> list = new ArrayList<>();
        switch (nodeName) {
            case NODE_CS_APPLY:
                if (expiredOverOneMonth(approveCase))
                    list.add(NODE_CHECK_CAR_NO);
                else
                    list.add(NODE_UPLOAD_FORM);
                break;
        }
        return list;
    }

    /**
     * 過期是否超過一個月
     */
    private boolean expiredOverOneMonth(DsgApproveCase approveCase) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("APP_NO", approveCase.getAppNo());
        DsgApplyCard card = cardService.getOne(wrapper);
        DsgApplyCard expiredCard = cardService.getById(card.getOldCardId());
        if (DateUtil.addHours(expiredCard.getCardEndDate(), 24 * 30).compareTo(new Date()) < 0) {
            return true;
        }
        return false;
    }
}
